using UnityEngine;
using UnityEngine.UI;

public class UILevelPanel : MonoBehaviour
{
	[SerializeField]
	private Image crownImage;

	[SerializeField]
	private Image backgroundImage;

	[SerializeField]
	private Image firstStar;

	[SerializeField]
	private Image secondStar;

	[SerializeField]
	private Image thirdStar;

	[SerializeField]
	private Text levelIdText;

	[SerializeField]
	private Color activeStartColour;

	[SerializeField]
	private WorldsColoursList worldsColours;

	private Button levelButton;

	private int worldId;

	private int levelId;

	private int progress;

	private bool crown;

	private int absoluteLevelId;

	private WorldColoursPalette palette;

	public void Initialize(int worldId, int levelId, int progress, bool crown, int absoluteLevelId)
	{
		this.absoluteLevelId = absoluteLevelId;
		this.levelId = levelId;
		this.worldId = worldId;
		this.progress = progress;
		this.crown = crown;
		palette = worldsColours.GetPalette(worldId);
		InitializePanel();
	}

	private void InitializePanel()
	{
		if (!crown)
		{
			crownImage.enabled = false;
		}
		if (progress < 3)
		{
			thirdStar.color = palette.inactiveStar;
		}
		else
		{
			thirdStar.color = activeStartColour;
		}
		if (progress < 2)
		{
			secondStar.color = palette.inactiveStar;
		}
		else
		{
			secondStar.color = activeStartColour;
		}
		if (progress < 1)
		{
			firstStar.color = palette.inactiveStar;
		}
		else
		{
			firstStar.color = activeStartColour;
		}
		levelIdText.text = levelId.ToString();
		levelButton = GetComponent<Button>();
		ColorBlock colors = levelButton.colors;
		colors.normalColor = palette.levelBackground;
		colors.highlightedColor = palette.levelBackground;
		colors.pressedColor = palette.levelBackgroundPressed;
		colors.disabledColor = palette.levelBackground;
		levelButton.colors = colors;
		backgroundImage.color = Color.white;
	}

	public void OnLevelPressed()
	{
		AudioController.instance.Play("button");
		Object.FindObjectOfType<GameController>().OnCustomLevelPicked(absoluteLevelId);
		Object.FindObjectOfType<UILevelsPicker>().Hide();
	}
}
